package com.cgnpc.scp.manager.controller;

import com.cgnpc.cud.annotation.OperatorType;
import com.cgnpc.cud.annotation.UBA;
import com.cgnpc.cud.core.domain.AjaxResult;
import com.cgnpc.scp.common.bean.MyPageResult;
import com.cgnpc.scp.common.utils.AjaxResultUtil;
import com.cgnpc.scp.manager.mybatis.entity.Debugtips;
import com.cgnpc.scp.manager.mybatis.entity.Systemconfig;
import com.cgnpc.scp.manager.service.DebugTipService;
import com.cgnpc.scp.manager.service.SystemConfigService;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/******************************
 * 用途说明: 常用系统设置
 * 作者姓名: heyachen
 * 创建时间: 2020/08/06 23:04
 ******************************/
@Controller
@RequestMapping("/scp/data/systemconfig")
public class SystemConfigController {


    private static final Logger LOGGER = LoggerFactory.getLogger(SystemConfigController.class);
    @Autowired
    private MessageSource messageSource;

    @Autowired
    private SystemConfigService systemConfigService;

    /**********************************
     * 用途说明: 保存信息
     * 参数说明 有ID更新。无ID保存
     * 返回值说明:
     ***********************************/
    @ApiOperation(value="保存常用系统设置")
    @UBA(module = "后台管理", action = "保存常用系统设置", channel = OperatorType.Button)
    @RequestMapping(value = "/saveOrUpdate", method = {RequestMethod.POST})
    @ResponseBody
    public Object saveOrUpdate(HttpServletRequest request, @RequestBody List<Systemconfig> systemconfigList) {
        try{
            int updateRows=systemConfigService.saveOrUpdate(systemconfigList);
            return AjaxResultUtil.createI18nDefaultSuccess(request,messageSource,updateRows);
        }catch (Exception e){
            LOGGER.error("SystemConfigController saveOrUpdate error : {}",e.getMessage(),e);
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
        }
    }
//    /**********************************
//     * 用途说明: 删除信息
//     * 参数说明 ids
//     * 返回值说明:
//     ***********************************/
//    @ApiOperation(value="删除信s息")
//    @RequestMapping(value = "/del", method = {RequestMethod.POST})
//    @ResponseBody
//    public Object del(HttpServletRequest request, @RequestBody List<String> ids) {
//        try{
//            int delete = systemConfigService.del(ids);
//            return AjaxResultUtil.createI18nDefaultSuccess(request,messageSource,delete);
//        }catch (Exception e){
//            LOGGER.error("SystemConfigController del error : {}",e.getMessage(),e);
//            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
//        }
//    }
    /**********************************
     * 用途说明: 分页查询
     * 参数说明 systemconfig
     * 返回值说明:
     ***********************************/
    @ApiOperation(value="分页查询")
    @UBA(module = "后台管理", action = "常用应用分页查询", channel = OperatorType.Button)
    @RequestMapping(value = "/loadByPaging", method = {RequestMethod.POST})
    @ResponseBody
    public Object loadByPaging(HttpServletRequest request) {
        try{
            List<Systemconfig> systemconfigMyPageResult = systemConfigService.loadByPaging();
            return AjaxResultUtil.createI18nDefaultSuccess(request,messageSource,systemconfigMyPageResult);
        }catch (Exception e){
            LOGGER.error("SystemConfigController loadByPaging error : {}",e.getMessage(),e);
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
        }
    }

}
